/*
 * Copyright Eduardo Aponte 2013
 * aponteeduardo@gmail.com
 */
#include <eyelink.h>
#include "mex.h"



void _main( ELINKADDR node )
{
    eyelink_set_tracker_node( node ); 
    return;
}


void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
    int i;
    /* Buffer size */
    int bs; 
    /* Matlab buffer: WARNING no protection against buffer over load */
    char *mb;
    /* Eyelink char. To support compatibility.*/
    ELINKADDR elb;
    
    
    /* Verify input arguments. */
    if(nrhs != 1 ) {
        mexErrMsgTxt("Incorrect number of inputs.");
    } else if( nlhs != 0 ) {
        mexErrMsgTxt("Too many output arguments.");
    }
    
    
    if ( mxIsChar(*prhs) != 1 )
      mexErrMsgTxt( "node must be a string.");
      
    mb  = mxArrayToString(*prhs);
    
    if(mb == NULL) 
      mexErrMsgTxt("Could not convert input to string.");
    
    bs  = (mxGetM(*prhs) * mxGetN(*prhs));

    if(bs != ELINKADDRSIZE)
        mexErrMsgTxt("node should be exactly 16 characters.");
        
    for (i = 0; i < ELINKADDRSIZE; i++)
        elb[i] = (byte ) mb[i];
      
    _main( elb );
    
    return;
    
}


